package com.cheetah.start.system.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cheetah.start.common.constant.SessionConst;
import com.cheetah.start.common.utils.MyServletUtil;
import com.cheetah.start.system.admin.domain.SysAdmin;
import com.cheetah.start.system.admin.mapper.SysAdminMapper;
import com.cheetah.start.system.admin.service.SysAdminService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Feel
 * @create 2021/7/18
 **/
@Service
public class SysAdminServiceImpl extends ServiceImpl<SysAdminMapper, SysAdmin> implements SysAdminService {


    @Override
    public SysAdmin getBySession() {
        HttpServletRequest request = MyServletUtil.getRequest();
        SysAdmin admin = null;
        try {
            admin = (SysAdmin) request.getSession().getAttribute(SessionConst.NAME);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (admin == null) {
            admin = new SysAdmin();
            admin.setName("没有登录");
        }
        return admin;
    }
}
